#include <bits/stdc++.h>

using namespace std;
int wpl = 0;
typedef struct node{
	char data;
	struct node *lch;
	struct node *rch;
}BTNode;
typedef struct node *BTree;
BTree CreateBtree(string str,int i);
int countwpl( BTree &BT,int len);
int main(){
	string str;
	BTree BT;
	BT = NULL;
	cin>>str;
	if( str=="#" ){
		cout<<"0"<<endl;
		return 0;
	}
	BT = CreateBtree( str,1 );
	cout<<countwpl( BT,0 );
}
BTree CreateBtree(string str,int i){
	if( str[i] =='#'||i>=str.size() ){
		return NULL;
	}
	BTree T = new node;
	T->data = str[i];
	T->lch = CreateBtree( str,2*i );
	T->rch = CreateBtree( str,2*i+1 );
	return T;
}
int countwpl( BTree &BT,int len ){
	if( !BT ) return 0;
	if( !BT->lch && !BT->rch){
		return (BT->data - '0')*len;
	}
	return countwpl( BT->lch,len+1 )+countwpl( BT->rch,len+1 );
}
